/* 
 * File:   PerlinTexture.h
 * Author: brady
 *
 * Created on May 8, 2011, 7:30 PM
 */

#include "Texture.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <stdio.h>

#ifndef PERLINTEXTURE_H
#define	PERLINTEXTURE_H


    //KEN PERLIN'S DEFINITIONS AND STATICS
    #define perlB 0x100
    #define perlBM 0xff
    #define perlN 0x1000
    #define perlNP 12   /* 2^N */
    #define perlNM 0xfff


    static int p[perlB + perlB + 2];
    static double g3[perlB + perlB + 2][3];
    static double g2[perlB + perlB + 2][2];
    static double g1[perlB + perlB + 2];
    static int start = 1;

    #define s_curve(t) ( t * t * (3. - 2. * t) )
    #define lerp(t, a, b) ( a + t * (b - a) )
    #define setup(i,b0,b1,r0,r1)\
            t = vec[i] + perlN;\
            b0 = ((int)t) & perlBM;\
            b1 = (b0+1) & perlBM;\
            r0 = t - (int)t;\
            r1 = r0 - 1.;
    #define at2(rx,ry) ( rx * q[0] + ry * q[1] )
    #define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] )

class PerlinTexture : public Texture{
public:
    PerlinTexture();
    PerlinTexture(Vector3D color1, Vector3D color2, int octaves);
    PerlinTexture(const PerlinTexture& orig);
    virtual ~PerlinTexture();
    Vector3D GetColorAt(const Vector3D& point);
    Vector3D GetNormalOffsetAt(const Vector3D& point); // </editor-fold>

protected:
    double Alpha;
    double Beta;
    int Octaves;
    double bumpScale;
    Vector3D Color1;
    Vector3D Color2;


    //BEGIN PERLIN'S HEADERS


    void init(void);
    double noise1(double);
    double noise2(double *);
    double noise3(double *);
    void normalize3(double *);
    void normalize2(double *);

    double PerlinNoise1D(double,double,double,int);
    double PerlinNoise2D(double,double,double,double,int);
    double PerlinNoise3D(double,double,double,double,double,int);

    //END PERLIN'S HEADERS

private:


};

#endif	/* PERLINTEXTURE_H */

